** Data reading and variable selection from raw data
** Korean General Social Survey 2004

** 01. Reading data **

cap log close
clear all
set more off
cd /*insert you work directory here*/
use /*read your data here*/ 


** 02. Consructing year and country variables **

ge year=2004
lab var year "survey year"

ge country=410
lab var country "ISO country code"
//Korea: 410 (ISO Country Codes) 


** 03. ID variables **

ge pid=RESPID
lab var pid "person id"

ge hhid=HHDNO
lab var hhid "household id"


** 04. Basic Demographics (Sex and Age/birth year) **

ge sex=SEX
lab var sex "sex"
lab def sex 1 "male" 2 "female"
lab val sex sex

ge age=AGE
lab var age "age"

ge birthyr = year - age

** 05. Siblings **

* number of brothers/sisters does not include respondent

ge nsibs=SIBNUM
lab var nsibs "number of siblings"

//missing

recode nsibs (77=.)

** 06. Own education **

rename EDUC educ_cat

ge educ_yrs = .
replace educ_yrs = 0 if educ_cat == 0
replace educ_yrs = 6 if educ_cat == 1
replace educ_yrs = 8 if educ_cat == 2
replace educ_yrs = 12 if educ_cat == 3
replace educ_yrs = 14 if educ_cat == 4
replace educ_yrs = 16 if educ_cat == 5
replace educ_yrs = 18 if educ_cat == 6
replace educ_yrs = 12 if educ_cat == 7


lab var educ_cat "highest level of education completed"


** 07. Parents' education: Father and/or Mother **

rename PAEDUC faeduc_cat

rename MAEDUC moeduc_cat

lab var faeduc_cat "father's education level"

lab var moeduc_cat "mother's education level"


ge faeduc_yrs = .
replace faeduc_yrs = 0 if faeduc_cat == 0
replace faeduc_yrs = 6 if faeduc_cat == 1
replace faeduc_yrs = 8 if faeduc_cat == 2
replace faeduc_yrs = 12 if faeduc_cat == 3
replace faeduc_yrs = 14 if faeduc_cat == 4
replace faeduc_yrs = 16 if faeduc_cat == 5
replace faeduc_yrs = 18 if faeduc_cat == 6
replace faeduc_yrs = 12 if faeduc_cat == 7

ge moeduc_yrs = .
replace moeduc_yrs = 0 if moeduc_cat == 0
replace moeduc_yrs = 6 if moeduc_cat == 1
replace moeduc_yrs = 8 if moeduc_cat == 2
replace moeduc_yrs = 12 if moeduc_cat == 3
replace moeduc_yrs = 14 if moeduc_cat == 4
replace moeduc_yrs = 16 if moeduc_cat == 5
replace moeduc_yrs = 18 if moeduc_cat == 6
replace moeduc_yrs = 12 if moeduc_cat == 7


// missing
recode faeduc_cat moeduc_cat (99=.) (88=.) (77=.)

** 08. Own occupation **

rename OCC occ_ISCO

rename EMPLY emp_stat

lab var occ_ISCO "current occupation_ISCO88"

lab var emp_stat "employment status"

// missing
recode occ_ISCO (77777=.) (88888=.) (99999=.)


** 09. Parents' occupation **

//not available

** 10. Tabulate the Identified Variables **

log using /*insert you work directory here*/, replace text

** Data reading and variable selection from raw data
** Chilean Social Mobility Survey

** Sex **
tab sex

** Age, Birth Year **
sum age birthyr, d

** Siblings **
sum nsibs, d

** R's Own Education **
tab1 educ_cat educ_yrs

** Parental Education **
tab1 faeduc_cat moeduc_cat faeduc_yrs moeduc_yrs

** R's Own Occupation **
tab1 occ_ISCO emp_stat

log close

** 11. Keep the identified variables only

keep year country pid hhid sex age birthyr ///
	 nsibs ///
	 educ_cat faeduc_cat moeduc_cat educ_yrs faeduc_yrs moeduc_yrs ///
	 emp_stat occ_ISCO


** 12. Save the Data File **

saveold /*insert you work directory here*/, replace

**Create ISCED Education Varible**

ge educ_ISCED = .
replace educ_ISCED = 000 if educ_cat == 0
replace educ_ISCED = 100 if educ_cat == 1
replace educ_ISCED = 200 if educ_cat == 2
replace educ_ISCED = 300 if educ_cat == 3
replace educ_ISCED = 400 if educ_cat == 4
replace educ_ISCED = 500 if educ_cat == 5
replace educ_ISCED = 600 if educ_cat == 6
replace educ_ISCED = 300 if educ_cat == 7

ge moeduc_ISCED = .
replace moeduc_ISCED = 000 if moeduc_cat == 0
replace moeduc_ISCED = 100 if moeduc_cat == 1
replace moeduc_ISCED = 200 if moeduc_cat == 2
replace moeduc_ISCED = 300 if moeduc_cat == 3
replace moeduc_ISCED = 400 if moeduc_cat == 4
replace moeduc_ISCED = 500 if moeduc_cat == 5
replace moeduc_ISCED = 600 if moeduc_cat == 6
replace moeduc_ISCED = 300 if moeduc_cat == 7

ge faeduc_ISCED = .
replace faeduc_ISCED = 000 if faeduc_cat == 0
replace faeduc_ISCED = 100 if faeduc_cat == 1
replace faeduc_ISCED = 200 if faeduc_cat == 2
replace faeduc_ISCED = 300 if faeduc_cat == 3
replace faeduc_ISCED = 400 if faeduc_cat == 4
replace faeduc_ISCED = 500 if faeduc_cat == 5
replace faeduc_ISCED = 600 if faeduc_cat == 6
replace faeduc_ISCED = 300 if faeduc_cat == 7


saveold /*insert you work directory here*/, replace
